package com.cinemate;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class SamplePageAdapter extends PagerAdapter {

    List<View> pages = null;
    int counter = 0;
    TextView text = null;

    public SamplePageAdapter(List<View> pages){
        this.pages = pages;
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position){
        View v = pages.get(position);
        ((ViewPager) collection).addView(v);
        return v;
    }

    @Override
    public void destroyItem(ViewGroup collection, int position, Object view){
        ((ViewPager) collection).removeView((View) view);
    }

    @Override
    public int getCount() {
        return pages.size();
    }

    @Override
    public void finishUpdate(ViewGroup arg0){
        int k = 0;

    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view.equals(o);
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1){
    }

    @Override
    public Parcelable saveState(){
        return null;
    }

    @Override
    public void startUpdate(ViewGroup arg0){
        ViewPager pager = (ViewPager) arg0;

        switch(pager.getCurrentItem()){
            case 0:
                text = (TextView) pages.get(0).findViewById(R.id.textview_newsite);
                text.setText(String.valueOf(counter));
                break;
            case 1:
                text = (TextView) pages.get(1).findViewById(R.id.textview_newcinema);
                text.setText(String.valueOf(counter));
                break;
            case 2:
                text = (TextView) pages.get(2).findViewById(R.id.textview_updatelist);
                text.setText(String.valueOf(counter));
                break;
            case 3:
                text = (TextView) pages.get(3).findViewById(R.id.textview_watchlist);
                text.setText(String.valueOf(counter));
                break;
        }
        counter++;

    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }


}
